<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加管理员-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="we-red">*</span>社团名
            </label>
            <div class="layui-input-inline">

                    <select id="name" name="name">
                        <option>请选择社团</option>
                    </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="we-red">*</span>活动标题
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="" lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="details" class="layui-form-label">
                <span class="we-red">*</span>活动简介
            </label>
            <div class="layui-input-inline">
                <textarea id="details" name="details" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="details" class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
        </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.extend({
        admin: '{/}../../static/js/admin'
    });
    layui.use(['form','layer','admin','jquery'], function(){
        var form = layui.form,
            admin = layui.admin,
            layer = layui.layer;
        var $ = layui.jquery;
        //form.render();
        window.onload = function (ev) {
            $.ajax({
                type: "get",
                url: '/api/organ/queryOrganList',
                contentType:'application/json;charset=UTF-8',
                success: function(res) {
                    var data = res.data;
                    if(res.code == 0) {
                        $.each(data, function(index,item) {
                            $('#name').append('<option value="'+item.id+'">'+item.name+'</option>');
                        });
                        form.render();
                    }
                }
            });
        }


        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            var name = $('#name').find( 'option:selected ').text();
            var f = data.field;
            var d = {
                "oid":f.name,
                "name":name,
                "title":f.title,
                "details":f.details,
                "status":1,
            };
            $.ajax({
                type: "post",
                url: '/api/organ/activity/insertOrganActivity',
                contentType:'application/json;charset=UTF-8',
                data:JSON.stringify(d),
                success: function(res) {
                    if(res.code == 0) {
                      layer.msg("增加成功");
                    }else{
                        layer.msg(data.msg);
                    }
                },
                fail: function () {
                    layer.msg("未知错误");
                }
            });
            return false;
        });

        return false;

    });
</script>
</body>

</html>